package com.hzy.fivepalace.admin.controller;

import com.hzy.fivepalace.admin.annotation.Login;
import com.hzy.fivepalace.admin.controller.base.BaseController;
import com.hzy.fivepalace.admin.service.AdminCommentService;
import com.hzy.fivepalace.common.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/admin/comment")
@Validated
@Api(tags = "评价服务")
@Login
public class AdminCommentController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(AdminCommentController.class);

    @Resource
    private AdminCommentService adminCommentService;

    /**
     * 用户评价列表
     *
     * @param userId
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/userCommentsList")
    @ApiOperation(value = "用户评价列表")
    public TableDataInfo myCommentsList(@ApiParam(value = "用户id:可对单个用户查询") @RequestParam(value = "userId", required = false) Integer userId,
                                        @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page,
                                        @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size) {

        return adminCommentService.getUserCommentList(userId, page, size);
    }

    /**
     * 商品评价列表
     *
     * @param goodsId
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/commentsList")
    @ApiOperation(value = "商品评价列表")
    public TableDataInfo list(@ApiParam(value = "商品ID")  @RequestParam @NotNull Integer goodsId,
                              @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page,
                              @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size) {

        return adminCommentService.getCommentList(goodsId, page, size);
    }

    /**
     * 回复评价
     * @param commentId
     * @param replyContent
     * @return
     */
    @PostMapping("/replyComments")
    @ApiOperation(value = "回复评价")
    public Object replyComments(@ApiParam(value = "评论ID")  @RequestParam @NotNull Integer commentId,
                                       @ApiParam(value = "回复内容")  @RequestParam @NotBlank String replyContent ) {

        return adminCommentService.replyComments(commentId, replyContent);
    }

}
